package fr.mk25.papervision3d.util{

    import fr.mk25.papervision3d.core.Position3D;
    import caurina.transitions.Tweener;
    import caurina.transitions.properties.CurveModifiers;
    import org.papervision3d.objects.DisplayObject3D;

    public class BezierTween{
        
        public function BezierTween(){}


        private static var _initiated:Boolean = false;

        public static function move(    displayObject3D:DisplayObject3D,
                                        end_position:Position3D, 
                                        start_position:Position3D=null, 
                                        bezierArray:Array=null, 
                                        duration:Number=10, 
                                        transition_type:String="linear"
                                    ):void{


            if(!_initiated){
                CurveModifiers.init();
                _initiated = true;
            }

            if(start_position ==  null){
                start_position = Position3D.getPosition3D(displayObject3D);
            }else{
               Position3D.setPosition3D(displayObject3D, start_position); 
            }

            var bezier_parameters:Array =new Array();

            var _b:Object = new Object();
            if(bezierArray!=null){
                if(bezierArray.length==1){
                    _b=bezierArray[0].toObject();
                 }else{
                    _b=new Array();
                    for(var i:int=0;i<bezierArray.length;i++){
                        _b.push(bezierArray[i].toObject() );
                    }
                }
            }

            Tweener.addTween(displayObject3D, {x:end_position.x, y:end_position.y, z:end_position.z, rotationX:end_position.rotationX, rotationY:end_position.rotationY, rotationZ:end_position.rotationZ, _bezier:_b, time:duration, transition:transition_type}); 
            
        }



    
    }

}
